package com.example.yeujian5.yuejian5.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.yeujian5.yuejian5.R;
import com.example.yeujian5.yuejian5.activity.ClubDetailActivity;
import com.example.yeujian5.yuejian5.bean.ClubBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by 7h0rns on 2017/11/7.
 */

public class ClubSearchAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context Contexts;
    private List<ClubBean> clubListsearch;
    private android.view.LayoutInflater LayoutInflater;
    public ClubSearchAdapter(Context Contexts, List<ClubBean> clubListList) {
        this.Contexts = Contexts;
        this.clubListsearch = clubListList;
        LayoutInflater = LayoutInflater.from(Contexts);
    }
    public void getSearchClub(List<ClubBean> clubListsearch)
    {
        this.clubListsearch= clubListsearch ;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.cluba_item, parent, false);

        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final  ClubBean entity=clubListsearch.get(position);
        final String club_name = entity.getClub_name();
        if (null==entity)return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.name.setText(entity.getClub_name());
        if (!entity.getThumb().isEmpty()){
            Picasso.with(Contexts).load("http://172.24.10.175/workout/Uploads/"+entity.getThumb()).into(viewHolder.pic);
        }else {
            viewHolder.pic.setImageResource(R.drawable.hh);
        }

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent =new Intent(Contexts,ClubDetailActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra("id",entity.getId());
                intent.putExtra("userid",entity.getUserid());
                intent.putExtra("clubname",entity.getClub_name());
                intent.putExtra("intro",entity.getIntroduction());
                intent.putExtra("address",entity.getProvince_name() + "-" + entity.getCity_name() + "-" + entity.getDistrict_name());
                intent.putExtra("phone",entity.getClub_tel());
                intent.putExtra("time",entity.getOpen_time());
                intent.putExtra("thumb",entity.getThumb());
                Contexts.startActivity(intent);

            }
        });

    }



    public class ViewHolder extends RecyclerView.ViewHolder {

        ImageView pic;
        TextView name;

        public ViewHolder(View itemView) {
            super(itemView);
            pic = (ImageView) itemView.findViewById(R.id.club_pic);
            name = (TextView) itemView.findViewById(R.id.club_name);

        }
    }

    @Override
    public int getItemCount() {
        return clubListsearch.size();
    }
}
